<html>
<head><meta charset="utf-8"><title>HashMap::raw_entry · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashMap.3A.3Araw_entry.html">HashMap::raw_entry</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="206473435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashMap%3A%3Araw_entry/near/206473435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashMap.3A.3Araw_entry.html#206473435">(Aug 10 2020 at 15:19)</a>:</h4>
<p>What's the path forward for stabilizing the <code>raw_entry</code> HashMap API? It's been present but unstable for a while, and has also been exposed publicly in <code>hashbrown</code> for just about as long without incident. Personally, the fact that you can get it by adding the <code>hashbrown</code> dep is the main reason I haven't been more bothersome about missing the functionality it adds...</p>
<ul>
<li>tracking issue: <a href="https://github.com/rust-lang/rust/issues/56167">https://github.com/rust-lang/rust/issues/56167</a></li>
<li>docs <a href="https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.raw_entry_mut">https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.raw_entry_mut</a> (well, there abouts anyway)</li>
</ul>
<p>I don't mind creating a stabilization PR if that's the path forward, but wanted to check.</p>



<a name="206477203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashMap%3A%3Araw_entry/near/206477203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashMap.3A.3Araw_entry.html#206477203">(Aug 10 2020 at 15:52)</a>:</h4>
<p>FWIW I don't really feel like it's quite as niche as the documentation implies, I very often want to defer creation of an owned key until it's needed. I've found it to meaningfully improve perf over entry for a few different kinds of workloads:</p>
<ul>
<li>
<p>Workloads where the key clone is expensive. (example case: I hit this when implementing a cache of SQL source code Strings to prepared statements).</p>
</li>
<li>
<p>Workloads where get-or-insert operations are common, but the "hit" rate is fairly high (example case: I've hit this when implementing string interning).</p>
</li>
</ul>
<p>(It's also just always been mildlly disappointing that there's no alternative for get-or-insert beyond 'do two lookups' and 'make an owned key every time you insert'...)</p>



<a name="206481468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashMap%3A%3Araw_entry/near/206481468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashMap.3A.3Araw_entry.html#206481468">(Aug 10 2020 at 16:28)</a>:</h4>
<p>IMO there are some serious issues with <code>RawEntry</code>. It definitely needs a proper API review and better documentation before being stabilized.</p>



<a name="206514252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashMap%3A%3Araw_entry/near/206514252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashMap.3A.3Araw_entry.html#206514252">(Aug 10 2020 at 21:14)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> Yeah i was starting to realized that when writing the 2nd comment... How far off from viable do you think it is?</p>
<p>To me, it looks like there are some fairly clear surface-level issues around naming/consistency and such, especially on the builders\*. I also agree about docs, at a minimum it should have examples the use cases it claims to be useful for...</p>
<p>Although, it's seems like you are talking about deeper issues, maybe?</p>
<p>\* I remember thinking that the original RawEntry proposal felt like it had a cleaner API there, although I guess it was infeasible... It does look like the builders were fixed in a bit of an ad-hoc way though, and i'm guessing not a ton of thought has been spent on it since then...</p>



<a name="206514516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashMap%3A%3Araw_entry/near/206514516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashMap.3A.3Araw_entry.html#206514516">(Aug 10 2020 at 21:18)</a>:</h4>
<p><span class="user-mention" data-user-id="209168">@Thom Chiovoloni</span> One issue that stood out is that <code>from_hash</code> and <code>search</code> methods on <code>RawEntryBuilderMut</code> both do the exact same thing.</p>



<a name="206514603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashMap%3A%3Araw_entry/near/206514603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashMap.3A.3Araw_entry.html#206514603">(Aug 10 2020 at 21:18)</a>:</h4>
<p>Basically the feature needs to someone to go through the API and make it consistent. And then add the missing documentation.</p>



<a name="206514973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashMap%3A%3Araw_entry/near/206514973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashMap.3A.3Araw_entry.html#206514973">(Aug 10 2020 at 21:21)</a>:</h4>
<p>I suggest experimenting in <code>hashbrown</code> first, which has a few API additions that <code>std</code> doesn't have (like <code>RawVacantEntryMut::insert_with_hasher</code>). Afterwards it will be trivial to port any API changes back to <code>std</code>.</p>



<a name="206515371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashMap%3A%3Araw_entry/near/206515371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashMap.3A.3Araw_entry.html#206515371">(Aug 10 2020 at 21:24)</a>:</h4>
<p>that makes sense. i was about to ask if hashbrown was the right place to take a stab, and i'm glad the answer is yes. not sure when i'll find time for that, in truth, but...  <span aria-label="grimacing" class="emoji emoji-1f62c" role="img" title="grimacing">:grimacing:</span></p>



<a name="214319754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/HashMap%3A%3Araw_entry/near/214319754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/HashMap.3A.3Araw_entry.html#214319754">(Oct 23 2020 at 14:24)</a>:</h4>
<p>Just passing by to say that it'd be wonderful to have this :-)</p>
<p><a href="https://github.com/rust-lang/rust/issues/56167">https://github.com/rust-lang/rust/issues/56167</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>